﻿using Microsoft.Win32;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tools.Core;

namespace Tools.Modules.Navigations.ViewModels
{
    public class AccessChooseViewModel : BindableBase, INavigationAware
    {
        private string _password=string.Empty;
        public string Password
        {
            get => _password;
            set=>SetProperty(ref _password, value);
        }

        public DelegateCommand ChooseAccessCommand { get; private set; }

        public AccessChooseViewModel()
        {
            ChooseAccessCommand = new DelegateCommand(() =>
            {
                OpenFileDialog ofd= new OpenFileDialog();
                ofd.Filter = "mdb文件|*.mdb";
                if (ofd.ShowDialog() == true)
                {
                    string path= ofd.FileName.Trim();
                    Password = Softwares.GetAccessPassword(path);
                }
            });
        }


        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return true;
        }

        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
        }

        public void OnNavigatedTo(NavigationContext navigationContext)
        {
        }
    }
}
